<?php
require_once ("../db/connectdatabase.php");
require_once ("../entitys/Card.php");

/*function getCards() {
	$con = new ConnectDB();
	$tbl = "card";
	$fn = array('id', 'bankid', 'intro', 'datecreate');
	$condetion = array('isuse' => true);
	return $con -> getvalueorderby($tbl, $fn, $condetion, 'datecreate');
}

function getCard($idcard) {
	$con = new ConnectDB();
	$tbl = "card";
	$fn = array('id', 'bankid', 'intro', 'datecreate');
	$condetion = array('id' => $idcard);
	return $con -> getvalue($tbl, $fn, $condetion);
}

function getCardByBank($bankid) {
	$con = new ConnectDB();
	$tbl = "card";
	$fn = array('id', 'bankid', 'intro', 'datecreate');
	$condetion = array('bankid' => $bankid, 'isuse' => true);
	return $con -> getvalueorderby($tbl, $fn, $condetion, 'datecreate');
}
*/
function insertCard($card) {
	$con = new ConnectDB();
	$tbl = "card";
	$fn = array('idcard' => ($card -> getID()), 'cardname' => ($card -> getCardName()), 'intro' => ($card -> getIntro()), 'imagecard' => ($card -> getImage()), 'bankid' => ($card -> getBank()), 'bankname' => ($card -> getBankName()), 'banklogo' => ($card -> getBankLogo()), 'datecreate' => ($card -> getDatecreate()));
	return $con -> insert($tbl, $fn);
}

function updateCard($card) {
	$con = new ConnectDB();
	$tbl = "card";
	$fn = array('cardname' => ($card -> getCardName()), 'intro' => ($card -> getIntro()), 'imagecard' => ($card -> getImage()), 'bankid' => ($card -> getBank()), 'bankname' => ($card -> getBankName()), 'banklogo' => ($card -> getBankLogo()), 'datecreate' => ($card -> getDatecreate()));
	$condition = array('idcard' => ($card -> getID()));
	return $con -> update($tbl, $fn, $condition);
}

function deleteCard($id) {
	$con = new ConnectDB();
	$tbl = "card";
	$fn = array('isuse' => false);
	$condition = array('idcard' => $id);
	return $con -> update($tbl, $fn, $condition);
}
?>